/*
 * File:   Node.cpp
 * Author: henrya
 *
 * Created on June 16, 2009, 3:05 PM
 */

#include "Node.h"
#include "Tokenizer.h"
#include "Network.h"
#include <cstdlib>
#include <iostream>

Node::Node(Network* network,int id) : network(network),id(id), interrupted(false) {
    RT = new RoutingTable(id,network->nodesIds);
}

Node::~Node() {
    delete RT;
}

void Node::addNeighbour(int id){
    neighboursIds.push_back(id);
}

Node* Node::createNode(Network* network,string& nodeConf){
    Tokenizer nodeTknzr(nodeConf);
    int id = atoi((*nodeTknzr.next()).c_str());
    cout<<"new Node: "<< id<<"\t with neigbours\t";
    Node* res=new Node(network,id);
    while(nodeTknzr.hasNext()){
    	int neigbourId=atoi((*nodeTknzr.next()).c_str());
        res->addNeighbour(neigbourId);
        cout<<neigbourId<<"\t";
    }
    cout<<endl;
    return res;
}

const int Node::getId(){
	return id;
}

void Node::run(){
    while(!interrupted){

    }
}

bool Node::studentSend(void *args){
    return false;
}

bool Node::studentRecv(void **args){
    return false;
}

void Node::printRT(){
//    RT->printRT();
}
